home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_vim.idb / usr / freeware / share / vim / syntax / c.vim.z / c.vim
Encoding:
Text File  |  1998-10-28  |  5.2 KB  |  132 lines

  1. " Vim syntax file
  2. " Language:    C
  3. " Maintainer:    Bram Moolenaar <Bram@vim.org>
  4. " Last change:    1998 Jan 6
  5.  
  6. " Remove any old syntax stuff hanging around
  7. syn clear
  8.  
  9. " A bunch of useful C keywords
  10. syn keyword cStatement    goto break return continue asm
  11. syn keyword cLabel        case default
  12. syn keyword cConditional    if else switch
  13. syn keyword cRepeat        while for do
  14.  
  15. syn keyword cTodo contained    TODO FIXME XXX
  16.  
  17. " String and Character constants
  18. " Highlight special characters (those which have a backslash) differently
  19. syn match cSpecial contained    "\\[0-7][0-7][0-7]\=\|\\."
  20. syn region cString        start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial
  21. syn match cCharacter        "'[^\\]'"
  22. syn match cSpecialCharacter    "'\\.'"
  23. syn match cSpecialCharacter    "'\\[0-7][0-7]'"
  24. syn match cSpecialCharacter    "'\\[0-7][0-7][0-7]'"
  25.  
  26. "catch errors caused by wrong parenthesis
  27. syn region cParen        transparent start='(' end=')' contains=ALLBUT,cParenError,cIncluded,cSpecial,cTodo,cUserLabel,cBitField
  28. syn match cParenError        ")"
  29. syn match cInParen contained    "[{}]"
  30.  
  31. "integer number, or floating point number without a dot and with "f".
  32. syn case ignore
  33. syn match cNumber        "\<[0-9]\+\(u\=l\=\|lu\|f\)\>"
  34. "floating point number, with dot, optional exponent
  35. syn match cFloat        "\<[0-9]\+\.[0-9]*\(e[-+]\=[0-9]\+\)\=[fl]\=\>"
  36. "floating point number, starting with a dot, optional exponent
  37. syn match cFloat        "\.[0-9]\+\(e[-+]\=[0-9]\+\)\=[fl]\=\>"
  38. "floating point number, without dot, with exponent
  39. syn match cFloat        "\<[0-9]\+e[-+]\=[0-9]\+[fl]\=\>"
  40. "hex number
  41. syn match cNumber        "\<0x[0-9a-f]\+\(u\=l\=\|lu\)\>"
  42. "syn match cIdentifier    "\<[a-z_][a-z0-9_]*\>"
  43. syn case match
  44. " flag an octal number with wrong digits
  45. syn match cOctalError        "\<0[0-7]*[89]"
  46.  
  47. if exists("c_comment_strings")
  48.   " A comment can contain cString, cCharacter and cNumber.
  49.   " But a "*/" inside a cString in a cComment DOES end the comment!  So we
  50.   " need to use a special type of cString: cCommentString, which also ends on
  51.   " "*/", and sees a "*" at the start of the line as comment again.
  52.   " Unfortunately this doesn't very well work for // type of comments :-(
  53.   syntax match cCommentSkip    contained "^\s*\*\($\|\s\+\)"
  54.   syntax region cCommentString    contained start=+"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
  55.   syntax region cComment2String    contained start=+"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
  56.   syntax region cComment    start="/\*" end="\*/" contains=cTodo,cCommentString,cCharacter,cNumber,cFloat
  57.   syntax match  cComment    "//.*" contains=cTodo,cComment2String,cCharacter,cNumber
  58. else
  59.   syn region cComment        start="/\*" end="\*/" contains=cTodo
  60.   syn match cComment        "//.*" contains=cTodo
  61. endif
  62. syntax match cCommentError    "\*/"
  63.  
  64. syn keyword cOperator    sizeof
  65. syn keyword cType        int long short char void size_t
  66. syn keyword cType        signed unsigned float double
  67. syn keyword cStructure    struct union enum typedef
  68. syn keyword cStorageClass    static register auto volatile extern const
  69.  
  70. syn region cPreCondit    start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\|elif\>\|else\>\|endif\>\)" skip="\\$" end="$" contains=cComment,cString,cCharacter,cNumber,cCommentError
  71. syn region cIncluded contained start=+"+ skip=+\\\\\|\\"+ end=+"+
  72. syn match cIncluded contained "<[^>]*>"
  73. syn match cInclude        "^\s*#\s*include\>\s*["<]" contains=cIncluded
  74. "syn match cLineSkip    "\\$"
  75. syn region cDefine        start="^\s*#\s*\(define\>\|undef\>\)" skip="\\$" end="$" contains=ALLBUT,cPreCondit,cIncluded,cInclude,cDefine,cInParen
  76. syn region cPreProc        start="^\s*#\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" contains=ALLBUT,cPreCondit,cIncluded,cInclude,cDefine,cInParen
  77.  
  78. " Highlight User Labels
  79. syn region    cMulti        transparent start='?' end=':' contains=ALLBUT,cIncluded,cSpecial,cTodo,cUserLabel,cBitField
  80. " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  81. syn match    cUserLabel    "^\s*\I\i*\s*:$"
  82. syn match    cUserLabel    ";\s*\I\i*\s*:$"ms=s+1
  83. syn match    cUserLabel    "^\s*\I\i*\s*:[^:]"me=e-1
  84. syn match    cUserLabel    ";\s*\I\i*\s*:[^:]"ms=s+1,me=e-1
  85.  
  86. " Avoid recognizing most bitfields as labels
  87. syn match    cBitField    "^\s*\I\i*\s*:\s*[1-9]"me=e-1
  88. syn match    cBitField    ";\s*\I\i*\s*:\s*[1-9]"me=e-1
  89.  
  90. syn sync ccomment cComment minlines=10
  91.  
  92. if !exists("did_c_syntax_inits")
  93.   let did_c_syntax_inits = 1
  94.   " The default methods for highlighting.  Can be overridden later
  95.   hi link cLabel    Label
  96.   hi link cUserLabel    Label
  97.   hi link cConditional    Conditional
  98.   hi link cRepeat    Repeat
  99.   hi link cCharacter    Character
  100.   hi link cSpecialCharacter cSpecial
  101.   hi link cNumber    Number
  102.   hi link cFloat    Float
  103.   hi link cOctalError    cError
  104.   hi link cParenError    cError
  105.   hi link cInParen    cError
  106.   hi link cCommentError    cError
  107.   hi link cOperator    Operator
  108.   hi link cStructure    Structure
  109.   hi link cStorageClass    StorageClass
  110.   hi link cInclude    Include
  111.   hi link cPreProc    PreProc
  112.   hi link cDefine    Macro
  113.   hi link cIncluded    cString
  114.   hi link cError    Error
  115.   hi link cStatement    Statement
  116.   hi link cPreCondit    PreCondit
  117.   hi link cType        Type
  118.   hi link cCommentError    cError
  119.   hi link cCommentString cString
  120.   hi link cComment2String cString
  121.   hi link cCommentSkip    cComment
  122.   hi link cString    String
  123.   hi link cComment    Comment
  124.   hi link cSpecial    SpecialChar
  125.   hi link cTodo        Todo
  126.   "hi link cIdentifier    Identifier
  127. endif
  128.  
  129. let b:current_syntax = "c"
  130.  
  131. " vim: ts=8
  132.